package com.dalongxin.work.data;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 采购计划Bean
 */
public class Buy implements Serializable {

    private int id;
    private int companyId;
    private String companyName;
    private int projectId;
    private String projectName;
    private String fillDate;
    private int totalNum;
    private double totalPrice;
    private double totalFee;
    private String remark;
    private int approveId1;
    private String approveName1;
    private int approveId2;
    private String approveName2;
    private int status;
    private int createId;
    private String createName;
    private String createTime;
    private List<Good> goodsList;

    /**
     * 采购的物料清单
     */
    public static class Good implements Serializable {
        private String goodsName;
        private double goodsPrice;
        private int goodsNum;
        private double goodsFee;

        public String getGoodsName() {
            return goodsName;
        }

        public void setGoodsName(String goodsName) {
            this.goodsName = goodsName;
        }

        public double getGoodsPrice() {
            return goodsPrice;
        }

        public void setGoodsPrice(double goodsPrice) {
            this.goodsPrice = goodsPrice;
        }

        public int getGoodsNum() {
            return goodsNum;
        }

        public void setGoodsNum(int goodsNum) {
            this.goodsNum = goodsNum;
        }

        public double getGoodsFee() {
            return goodsFee;
        }

        public void setGoodsFee(double goodsFee) {
            this.goodsFee = goodsFee;
        }

        public static Good parseFromJson(JSONObject jsonObject) {
            Good good = new Good();
            good.goodsName = jsonObject.optString("goodsName");
            good.goodsPrice = jsonObject.optDouble("goodsPrice");
            good.goodsNum = jsonObject.optInt("goodsNum");
            good.goodsFee = jsonObject.optDouble("goodsFee");
            return good;
        }

        public static List<Good> parseFromJsonList(JSONArray jsonArray) {
            List<Good> list = new ArrayList<>();
            if(jsonArray != null && jsonArray.length() > 0) {
                for(int i=0;i<jsonArray.length();i++) {
                    Good item = parseFromJson(jsonArray.optJSONObject(i));
                    if(item != null)list.add(item);
                }
            }
            return list;
        }
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getCompanyId() {
        return companyId;
    }

    public void setCompanyId(int companyId) {
        this.companyId = companyId;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public int getProjectId() {
        return projectId;
    }

    public void setProjectId(int projectId) {
        this.projectId = projectId;
    }

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public String getFillDate() {
        return fillDate;
    }

    public void setFillDate(String fillDate) {
        this.fillDate = fillDate;
    }

    public int getTotalNum() {
        return totalNum;
    }

    public void setTotalNum(int totalNum) {
        this.totalNum = totalNum;
    }

    public double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(double totalPrice) {
        this.totalPrice = totalPrice;
    }

    public double getTotalFee() {
        return totalFee;
    }

    public void setTotalFee(double totalFee) {
        this.totalFee = totalFee;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public int getApproveId1() {
        return approveId1;
    }

    public void setApproveId1(int approveId1) {
        this.approveId1 = approveId1;
    }

    public String getApproveName1() {
        return approveName1;
    }

    public void setApproveName1(String approveName1) {
        this.approveName1 = approveName1;
    }

    public int getApproveId2() {
        return approveId2;
    }

    public void setApproveId2(int approveId2) {
        this.approveId2 = approveId2;
    }

    public String getApproveName2() {
        return approveName2;
    }

    public void setApproveName2(String approveName2) {
        this.approveName2 = approveName2;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getCreateId() {
        return createId;
    }

    public void setCreateId(int createId) {
        this.createId = createId;
    }

    public String getCreateName() {
        return createName;
    }

    public void setCreateName(String createName) {
        this.createName = createName;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public List<Good> getGoodsList() {
        return goodsList;
    }

    public void setGoodsList(List<Good> goodsList) {
        this.goodsList = goodsList;
    }

    public static Buy parseFromJson(JSONObject jsonObject) {
        Buy buy = new Buy();
        buy.id = jsonObject.optInt("id");
        buy.companyId = jsonObject.optInt("companyId");
        buy.companyName = jsonObject.optString("companyName");
        buy.projectId = jsonObject.optInt("projectId");
        buy.projectName = jsonObject.optString("projectName");
        buy.fillDate = jsonObject.optString("fillDate");
        buy.totalNum = jsonObject.optInt("totalNum");
        buy.totalPrice = jsonObject.optDouble("totalPrice");
        buy.totalFee = jsonObject.optDouble("totalFee");
        buy.remark = jsonObject.optString("remark");
        buy.approveId1 = jsonObject.optInt("approveId1");
        buy.approveName1 = jsonObject.optString("approveName1");
        buy.approveId2 = jsonObject.optInt("approveId2");
        buy.approveName2 = jsonObject.optString("approveName2");
        buy.status = jsonObject.optInt("status");
        buy.createId = jsonObject.optInt("createId");
        buy.createName = jsonObject.optString("createName");
        buy.createTime = jsonObject.optString("createTime");
        buy.goodsList = Good.parseFromJsonList(jsonObject.optJSONArray("goodsList"));
        return buy;
    }

    public static List<Buy> parseFromJsonList(JSONArray jsonArray) {
        List<Buy> list = new ArrayList<>();
        if(jsonArray != null && jsonArray.length() > 0) {
            for(int i=0;i<jsonArray.length();i++) {
                Buy item = parseFromJson(jsonArray.optJSONObject(i));
                if(item != null)list.add(item);
            }
        }
        return list;
    }
}
